<?php
/**
 * FastApp.
 * 8/21/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateMallTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('mall_shop', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商店');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->bigInteger('admin_id')->nullable()->unsigned();
            $table->timestamp('deleted_at')->nullable();
            $table->addColumn('bigInteger', 'created_by', ['comment' => '创建者'])->nullable();
            $table->addColumn('bigInteger', 'updated_by', ['comment' => '更新者'])->nullable();
            $table->char('logo', 64)->nullable()->comment('logo');
            $table->json('name')->nullable()->comment('名称');
            $table->json('content')->nullable()->comment('介绍');
            $table->index('admin_id');
        });
        Schema::create('mall_category', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('分类表');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->timestamp('deleted_at')->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(0);
            $table->bigInteger('parent_id')->nullable()->comment('上级')->unsigned()->default(0);
            $table->tinyInteger('status')->nullable()->comment('1显示')->unsigned()->default(1);
            $table->bigInteger('shop_id')->nullable()->default(0)->unsigned();
            $table->index('shop_id');
        });
        Schema::create('mall_tag', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('标签表');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->timestamp('deleted_at')->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(0);
            $table->bigInteger('shop_id')->nullable()->default(0)->unsigned();
            $table->index('shop_id');
        });
        Schema::create('mall_brand', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('品牌表');
            $table->bigIncrements('id')->comment('主键');
            $table->string('name', 32);
            $table->string('image', 64)->nullable()->default('');
            $table->bigInteger('shop_id')->nullable()->default(0)->unsigned();
            $table->index('shop_id');
        });
        Schema::create('mall_goods', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商品');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->timestamp('deleted_at')->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->json('title')->nullable()->comment('标题');
            $table->json('images')->nullable()->comment('展示图');
            $table->char('no', 32)->nullable()->comment('商品编码');
            $table->bigInteger('shop_id')->nullable()->comment('shop_id')->default(0)->unsigned();
            $table->tinyInteger('is_spec')->nullable()->comment('is_spec')->default(0)->unsigned();
            $table->tinyInteger('check_stock')->nullable()->comment('检测库存')->default(0)->unsigned();
            $table->tinyInteger('is_virtual')->nullable()->comment('虚拟商品')->default(1)->unsigned();
            $table->tinyInteger('is_arrival')->nullable()->comment('到店')->default(0)->unsigned();
            $table->tinyInteger('online')->nullable()->comment('上架')->default(0)->unsigned();
            $table->tinyInteger('buy_limit')->nullable()->comment('限购数')->default(0)->unsigned();
            $table->tinyInteger('is_integral')->nullable()->comment('积分')->default(0)->unsigned();
            $table->bigInteger('comments')->nullable()->comment('评论数')->default(0)->unsigned();
            $table->bigInteger('views')->nullable()->comment('浏览数')->default(0)->unsigned();
            $table->bigInteger('collects')->nullable()->comment('收藏数')->default(0)->unsigned();
            $table->bigInteger('sort')->nullable()->comment('排序')->default(0)->unsigned();
            $table->decimal('costprice')->nullable()->comment('成本价')->default(0);
            $table->decimal('mktprice')->nullable()->comment('市场价')->default(0);
            $table->bigInteger('tmp_id')->nullable()->comment('展示模版')->default(0)->unsigned();
            $table->bigInteger('brand_id')->nullable()->comment('品牌');
            $table->json('content')->nullable()->comment('商品介绍');
            $table->index('shop_id');
            $table->index('brand_id');
        });
        Schema::create('mall_goods_spec', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商品规格');
            $table->bigIncrements('id')->comment('主键');
            $table->json('name')->nullable()->comment('规格');
            $table->char('image', 64)->nullable()->comment('image');
            $table->tinyInteger('is_default')->nullable()->default(0)->unsigned();
            $table->bigInteger('goods_id')->nullable()->comment('goods_id')->default(0)->unsigned();
            $table->bigInteger('stock')->nullable()->comment('库存')->default(0)->unsigned();
            $table->bigInteger('sells')->nullable()->comment('卖出数')->default(0)->unsigned();
            $table->bigInteger('return')->nullable()->comment('退货数')->default(0)->unsigned();
            $table->index('goods_id');
        });
        Schema::create('mall_goods_price', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商品价格');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('goods_id')->nullable()->comment('goods_id')->default(0)->unsigned();
            $table->bigInteger('spec_id')->nullable()->comment('spec_id')->default(0)->unsigned();
            $table->char('symbol', 8)->nullable()->comment('币种');
            $table->decimal('price', 11)->nullable()->comment('售价')->default(0);
            $table->index('goods_id');
            $table->index('symbol');
        });
        Schema::create('mall_goods_category', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商品分类');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('goods_id')->unsigned();
            $table->bigInteger('category_id')->unsigned();
            $table->index('category_id');
            $table->index('goods_id');
        });
        Schema::create('mall_goods_tag', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('商品标签');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('goods_id')->unsigned();
            $table->bigInteger('tag_id')->unsigned();
            $table->index('tag_id');
            $table->index('goods_id');
        });
        Schema::create('mall_goods_shop', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('店铺商品');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('goods_id')->unsigned();
            $table->bigInteger('shop_id')->unsigned();
            $table->index('shop_id');
            $table->index('goods_id');
        });
        Schema::create('mall_order', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('订单');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->timestamp('deleted_at')->nullable();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('no', 32)->comment('订单编号');
            $table->char('source', 16)->comment('来源game,mall')->default('mall');
            $table->decimal('total_amount', 11)->comment('总金额');
            $table->decimal('pay_amount', 11)->comment('支付金额');
            $table->tinyInteger('is_pay')->comment('支付0否1是2退款')->unsigned()->default(0);
            $table->timestamp('pay_at')->nullable();
            $table->tinyInteger('status')->comment('1正常2取消3超时')->unsigned()->default(1);
            $table->char('ship_name')->nullable()->comment('收货人');
            $table->char('ship_phone')->nullable()->comment('收货电话');
            $table->char('ship_address')->nullable()->comment('收货地址');
            $table->bigInteger('shop_id')->nullable()->default(0)->unsigned();
            $table->char('symbol', 8);
            $table->unique('no');
            $table->index('user_id');
            $table->index('shop_id');
            $table->index('symbol');
        });
        Schema::create('mall_order_item', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('订单商品');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('order_id')->comment('订单id')->unsigned();
            $table->bigInteger('goods_id')->comment('商品id')->unsigned();
            $table->char('sub_no', 32)->comment('子订单编号');
            $table->char('symbol', 8);
            $table->decimal('price', 11)->comment('商品价格');
            $table->decimal('pay_amount', 11)->comment('支付价格');
            $table->smallInteger('num')->comment('数量');
            $table->char('cover')->comment('封面');
            $table->char('name')->comment('商品名称');
            $table->char('spec')->comment('规格');
            $table->bigInteger('shop_id')->nullable()->default(0)->unsigned();
            $table->index('order_id');
            $table->unique('sub_no');
            $table->index('shop_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('mall_shop');
        Schema::dropIfExists('mall_category');
        Schema::dropIfExists('mall_tag');
        Schema::dropIfExists('mall_brand');
        Schema::dropIfExists('mall_goods');
        Schema::dropIfExists('mall_goods_spec');
        Schema::dropIfExists('mall_goods_price');
        Schema::dropIfExists('mall_goods_category');
        Schema::dropIfExists('mall_goods_tag');
        Schema::dropIfExists('mall_goods_shop');
        Schema::dropIfExists('mall_order');
        Schema::dropIfExists('mall_order_item');
    }
}
